//
//  RSChatMessage.m
//  ReplayStar
//
//  Created by Félix Cloutier on 11-11-02.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "RSChatMessage.h"

@implementation RSChatMessage

@synthesize player;
@synthesize time;
@synthesize body;
@synthesize target;

-(id)initWithPlayer:(RSPlayerData *)aPlayer target:(RPReplayMessageTarget)aTarget time:(NSTimeInterval)aTime message:(NSString *)aMessage
{
	if (!(self = [super init])) return nil;
	
	player = [aPlayer retain];
	time = aTime;
	body = [aMessage copy];
	target = aTarget;
	
	return self;
}

-(NSString*)description
{
	NSString* targetName = target == RPReplayMessageTargetAll ? @"All" : @"Allies";
	unsigned flooredTime = time;
	unsigned hours = flooredTime / 3600;
	unsigned minutes = (flooredTime % 3600) / 60;
	unsigned seconds = flooredTime % 60;
	return [NSString stringWithFormat:@"[%02u:%02u:%02u] <%@ to %@> %@", hours, minutes, seconds, player.name, targetName, body];
}

-(void)dealloc
{
	[player release];
	[body release];
	[super dealloc];
}

@end
